package com.faw.fengyue.rfid.core;

import android.os.Build;

import java.util.UUID;

public class DeviceIdentifier {

    public static String getUUID() {
        String serial = null;
        String m_szDevIDShort = "随机两位数" +
                Build.BOARD.length() % 10 + Build.BRAND.length() % 10 +
                Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 +
                Build.DISPLAY.length() % 10 + Build.HOST.length() % 10 +
                Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 +
                Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 +
                Build.TAGS.length() % 10 + Build.TYPE.length() % 10 +
                Build.USER.length() % 10; //13 位
        try {
            serial = android.os.Build.getSerial();
            
//            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//                serial = android.os.Build.getSerial();
//            } else {
//                serial = Build.SERIAL;
//            }
            //API>=9 使用serial号
            return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
        } catch (Exception exception) {
            //serial需要一个初始化
            serial = "默认值"; // 随便一个初始化
        }
        //使用硬件信息拼凑出来的15位号码
        return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
    }

    /**
     * 获取deviceId(手机唯一的标识)
     *
     * @param context
     * @return
     */
//    @SuppressLint({"HardwareIds", "NewApi", "MissingPermission"})
//    public static String getDeviceId(Context context) {
//        String deviceId;
//        deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
//            deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
//        } else {
//            final TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
//            if (context.checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
//                return "";
//            }
//            assert mTelephony != null;
//            if (mTelephony.getDeviceId() != null) {
//                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//                    deviceId = mTelephony.getImei();
//                } else {
//                    deviceId = mTelephony.getDeviceId();
//                }
//            } else {
//                deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
//            }
//        }
//        return deviceId;
//    }
}
